package com.cn.study0013;

import java.util.Scanner;

/**
 * @author lw
 * @ClassName Goods.java
 * @Description
 * @createTime 2023年05月20日
 */
public class Goods {
    String[] shop = new String[]{"电风扇", "洗衣机", "电视机", "冰 箱", "空调机"};
    double[] price = new double[]{124.23, 4500.0, 8800.9, 5000.88, 4456.0};
    Scanner sc = new Scanner(System.in);

    public void show() {
        StringBuffer[] str = new StringBuffer[price.length];
        for (int j = 0; j < price.length; j++) {
            str[j] = change(price[j]);
        }
        System.out.println("********欢迎进入商品批发城**************");
        System.out.println("\t\t\t"+"编号"+ "\t\t\t"+"商品"+"\t\t\t"+"价格");
        System.out.println("----------------------------------");
        for (int j = 0; j < shop.length; j++) {
            System.out.println("\t\t\t"+(j+1)+"\t\t"+shop[j] + "\t\t"+str[j]);
        }
        System.out.println("**********************************");
        System.out.print("请输入你要批发的商品编号：");
        int shid = sc.nextInt();
        System.out.print("请输入批发数量：");
        int num= sc.nextInt();
        System.out.print("您需要付款：");
        StringBuffer s = change(num*price[shid -1]);
        System.out.println(s);
    }

    public StringBuffer change(double d) {
        StringBuffer sb = new StringBuffer(String.valueOf(d));
        for (int i = sb.indexOf(".") - 3; i > 0; i = i - 3) {
            sb.insert(i, ",");
        }
        return sb;
    }
}
